package com.qf.service.impl;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.FilterChainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/*
 *@Description:路由策略
 *@author:刘哥
 *@Date:86180 2022/10/19 17:46
 */
@Service("router")
@Slf4j
public class RouterServiceImpl implements FilterChainService {
    /*
        创建队列对象
     */
    @Autowired
    private AmqpAdmin amqpAdmin;
    /*
        发送对象
     */
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public boolean strategy(StandardSubmit standardSubmit) {
        log.info("[策略模块-路由策略] 开始执行==========");
//        封装接收方的队列名称
        String queueName = RabbitMQConstants.TOPIC_SMS_GATEWAY + standardSubmit.getGatewayID();
//      创建指定的队列,如果队列存在不创建
        String queue = amqpAdmin.declareQueue(QueueBuilder.durable(queueName).build());
//        发送消息到指定的队列中
        rabbitTemplate.convertAndSend(queueName, standardSubmit);

//        记录日志
        log.info("[策略模块-路由策略] 路由模块执行完毕========== standardSubmit={} ",standardSubmit);
        return true;
    }
}
